package com.raptor.rabbitmq.product;

import com.raptor.rabbitmq.common.RabbitConstant;
import com.raptor.rabbitmq.common.Send;
import com.raptor.rabbitmq.common.SpringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class ProductExchangeApplocationContextAware implements ApplicationContextAware {


    private static final Logger logger = LoggerFactory.getLogger(DelegateRabbitMQProducerConfiguration.class);


    public static Map<String, Send> map = new ConcurrentHashMap<String, Send>();


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        logger.info("初始化 rabbitmq Exchange 类型 ");
        map.put(RabbitConstant.CUSTOMER, (Send) SpringUtil.getBean(RabbitConstant.CUSTOMER));
        map.put(RabbitConstant.DIRECT, (Send) SpringUtil.getBean(RabbitConstant.DIRECT));
        map.put(RabbitConstant.FANOUT, (Send) SpringUtil.getBean(RabbitConstant.FANOUT));
        map.put(RabbitConstant.TOPIC, (Send) SpringUtil.getBean(RabbitConstant.TOPIC));
        map.forEach((k, v) -> {
            logger.info("rabbitmq Exchange  " + k + " 类型");
        });
    }
}
